package com.kobe.game_40;

/**
 * 
 * If p is the perimeter of a right angle triangle with integral length sides,
 * {a,b,c}, there are exactly three solutions for p = 120.
 * 
 * {20,48,52}, {24,45,51}, {30,40,50}
 * 
 * For which value of p ≤ 1000, is the number of solutions maximised?
 * 
 * 
 */
public class Game39 {

    public static int getSolution(int number) {
        int solution = 0;
        for (int a = 1; a <= number / 3; a++) {
            for (int b = a; b <= (number - a) / 2; b++) {
                int c = number - a - b;
                if (a * a + b * b == c * c) {
                    solution++;
                    System.out.println(a + "" + b + "" + c);
                }
            }
        }

        return solution;
    }

    public static void main(String[] args) {
        int solution = 0;
        int tempSolution = 0;
        int p = 0;
        for (int i = 1; i <= 1000; i++) {
            tempSolution = getSolution(i);
            if (tempSolution > solution) {
                solution = tempSolution;
                p = i;
            }
        }
        System.out.println(p);
    }
}
